package br.ifrr.gepro.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

public class DateUtil {

    public static Date formataData(String data) {
        if (!data.equals("")) {
            try {
                SimpleDateFormat dataFormat = new SimpleDateFormat("dd/MM/yyyy");
                Date data2 = dataFormat.parse(data);
                return data2;
            } catch (ParseException ex) {
                Logger.getLogger(DateUtil.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return null;
    }

    public static String formataData(Date data) {
        if (data != null) {
            SimpleDateFormat dataFormat = new SimpleDateFormat("yyyy-MM-dd");
            return dataFormat.format(data);
        }
        return "";
    }

    public static String formataDataBrasil(Date data) {
        if (data != null) {
            SimpleDateFormat dataFormat = new SimpleDateFormat("dd/MM/yyyy");
            return dataFormat.format(data);
        }
        return "";
    }

    public static Date addFusoHorario(Date d) {
        return new Date(d.getTime() + 21600000l);
    }

    public static java.sql.Date formataDataSql(Date data) {
        return new java.sql.Date(data.getYear(), data.getMonth(), data.getDay());
    }
}
